package edu.utd.text.game.tests;

import junit.framework.Assert;
import junit.framework.TestCase;
import edu.utd.text.game.domain.GameObject;
import edu.utd.text.game.domain.item.GameItem;
import edu.utd.text.game.tests.mocks.FakeAxe;
import edu.utd.text.game.tests.mocks.FakeKnife;
import edu.utd.text.game.tests.mocks.FakeShovel;

public class TestGameItem extends TestCase {

	//GameItem must be subclassed, so create one here:
	class GameItemSubclass extends GameItem {
		public GameItemSubclass(String name) {
			super(name);
		}
		public String getDescription() { return "Description for GameItemSubclass"; }
	}
	
	class GameItemSubSubclass extends GameItemSubclass {
		public GameItemSubSubclass(String name) {
			super(name);
		}
	}
	
	class GameObjectSubclass extends GameObject {
		public GameObjectSubclass(String name) { setName(name); }
		public String getDescription() { return "A subclass of GameObject"; }
	}
	
	public void testCreateGameItem() {
		GameObject gameItem = new GameItemSubclass("A Name");
		Assert.assertEquals("A Name", ((GameItem)gameItem).getName());
	}
	
	public void testEqualsMethod() {
		//use the mock objects here
		
		//any gameItems of the same type should be equal
		FakeAxe axe1 = new FakeAxe();
		FakeAxe axe2 = new FakeAxe();
		//these 2 should be equal
		if(!axe1.equals(axe2))
			fail("WRONG: 2 GameItems of same type did not come back as equal.");
		axe1.setName("My Axe");
		axe2.setName("My totally sweet rockin axe");
		//TODO: you can only have one type of item at a time, they should not 
		//be different like this though...
		//should they be singletons?
		if(axe1.equals(axe2))
			fail("WRONG: 2 GameItems of same type but w/ diff name attribs came back as equal.");
		
		
		GameObject knife = new FakeKnife();
		GameObject shovel = new FakeShovel();
		if(knife.equals(shovel))
			fail("WRONG: a knife and a shovel are not the same thing!");
		
		//test equals() with subclassing
		GameItem subclass1 = new GameItemSubclass("subclass1");
		GameItem subclass2 = new GameItemSubSubclass("subclass2");
		
		Assert.assertTrue(!subclass1.equals(subclass2));
		
		GameObject gameObject1 = new GameObjectSubclass("sub");
		GameObject gameObject2 = new GameObjectSubclass("sub");
		GameObject gameObject3 = new GameObjectSubclass("!sub");
		
		Assert.assertTrue(gameObject1.equals(gameObject2));
		Assert.assertTrue(!gameObject1.equals(gameObject3));
	}
	
}
